import React, {useRef, useState} from 'react';
import {message, Card, Upload, Button, Form} from 'antd';
import {useRequest} from "@@/plugin-request/request";
import { addAgentAccount, merchantList, queryAgentByWhatsApp, uploadAccount } from "@/services/bz/api";
import {
  ProForm, ProFormInstance,
  ProFormSelect, ProFormText,ProFormDatePicker
} from "@ant-design/pro-components";
import {UploadOutlined} from "@ant-design/icons";


const handleChange = (value: string) => {
  console.log(`selected ${value}`);
};

export default () => {
  const [merchantData, setMerchantData] = useState([]);
  const [agentName, setAgentName] = useState("");
  const ref = useRef<ProFormInstance>();

  useRequest(merchantList, {
    onSuccess: (res) => {
      let data = [];
      //将拿到的返回值遍历
      res.list.map(item => {
        data.push({
          label: item.merchantCode,
          value: item.merchantCode
        })
      });
      setMerchantData(data);
      console.log("===", merchantData)
    },
  });
  return (
    <div>
      <Card>
        <h3>查询WhatsApp</h3>
        <ProForm
          title={"查询坐席"}
          formRef={ref}
          onFinish={async (values:API.QueryAgentByWhatsAppBean) => {
            if (values.date == undefined) {
              message.error('请选择查询日期');
              return
            }
            if (values.whatsApp == undefined) {
              message.error('请输入要查询的whatsApp');
              return
            }
            setAgentName("")
            await queryAgentByWhatsApp(values.date,values.whatsApp).then((res) => {
              message.success(res.msg);
              setAgentName(res.data)
              ref.current?.resetFields()
            },reason => {
              message.error(reason.data.msg);
            })

          }}
          request={async (data) => {
            console.log("====", data)
            return {};
          }}
        >
          <ProFormDatePicker colProps={{ xl: 8, md: 12 }} label="选择日期" name="date" />

          <ProFormText width="md" name="whatsApp" label="WhatsApp" placeholder="请输入WhatsApp" />
          <p>催收队长:{agentName}</p>
        </ProForm>
      </Card>
    </div>

  )
}
